package top.letscode.adclicker.ad;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import top.letscode.adclicker.annotation.Union;
import top.letscode.adclicker.driver.WebDriverHelper;
import top.letscode.adclicker.util.Constants;
import top.letscode.adclicker.util.RandomUtil;

@Union(name = "caiping", desc = "彩屏联盟http://www.9cp.cn/Webmaster/main.php",
    type = Constants.UNION_TYPE_MOBILE)
public class CaiPingUnion extends AbstractUnion {

  @Override
  public void click(WebDriver webDriver) {
    System.out.println("start click caiping ad...");
    WebElement iframe = WebDriverHelper.findElement(By.xpath("//iframe[position()=1]"));
    int width = RandomUtil.randomInt(iframe.getSize().getWidth());
    int height = RandomUtil.randomInt(iframe.getSize().getHeight());

    Actions actions = new Actions(webDriver);
    // 随机一个坐标点击
    actions.moveToElement(iframe, width, height).click().perform();
  }

  @Override
  public float getRate() {
    return ((1.0f * RandomUtil.randomInt(3)) / 100) + 0.05f;
  }
}
